package com.zjt.swipeview.demo;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import java.util.List;

/**
 * <p>Title: </p>
 * <p>Description: </p>
 * <p>Copyright: Copyright (c) 2017</p>
 * <P>Company: </p>
 *
 * @author zhengjianting
 * @time 2017/11/23 0023 下午 5:33
 */

public class SampleAdapter extends RecyclerView.Adapter<SampleAdapter.SampleHolder> {

    private Context mContext;
    private List<String> dataList;

    public SampleAdapter(Context context, List<String> dataList) {
        this.mContext = context;
        this.dataList = dataList;
    }

    @Override
    public SampleHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new SampleHolder(LayoutInflater.from(mContext), parent);
    }

    @Override
    public void onBindViewHolder(SampleHolder holder, int position) {
        holder.getTextView().setText(dataList.get(position));
    }

    @Override
    public int getItemCount() {
        return dataList.size();
    }

    public void cleanData(){
        dataList.clear();
        notifyDataSetChanged();
    }

    public void addData(List<String> dataList){
        this.dataList.addAll(dataList);
        notifyDataSetChanged();
    }

    public static class SampleHolder extends RecyclerView.ViewHolder{

        private TextView textView;

        public SampleHolder(View itemView) {
            super(itemView);
            textView = (TextView) itemView.findViewById(R.id.tv_num);
        }

        public SampleHolder(LayoutInflater inflater, ViewGroup parent) {
            this(inflater.inflate(R.layout.item_sample, parent, false));
        }

        public TextView getTextView() {
            return textView;
        }

        public void setTextView(TextView textView) {
            this.textView = textView;
        }
    }
}
